package com.dream.testtubebaby.adapter;

import java.util.List;

import android.content.Context;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.dream.testtubebaby.R;
import com.dream.testtubebaby.data.AddToldData;
import com.dream.testtubebaby.utils.ViewHolder;

public class MyToldListAdapter extends CommonAdapter<AddToldData> {

	public interface ToldDetailListener {
		void onToldDetailonClick(AddToldData item);
	}

	private ToldDetailListener mToldDetailListener;

	public void setToldDetailListener(ToldDetailListener listener) {
		mToldDetailListener = listener;
	}

	public MyToldListAdapter(Context context, List<AddToldData> mDatas,
			int itemLayoutId) {
		super(context, mDatas, itemLayoutId);
	}

	@Override
	public void convert(final ViewHolder helper, final AddToldData item) {
		helper.setText(R.id.told_project_tv, item.getStepname());
		helper.setText(R.id.told_start_time_tv, item.getFromtime());
		ImageView told_edit_icon = helper.getView(R.id.told_edit_icon);
		if (item.getFinishtime() != 0) {
//			CharSequence time_string = DateUtils.getRelativeTimeSpanString(
//					item.getFinishtime(), System.currentTimeMillis(),
//					DateUtils.MINUTE_IN_MILLIS,
//					DateUtils.FORMAT_ABBREV_RELATIVE);
//			helper.setText(R.id.told_end_time_tv, time_string.toString());
			helper.setText(R.id.told_end_time_tv, item.getTotime());
			told_edit_icon.setEnabled(false);
		} else {
			helper.setText(R.id.told_end_time_tv, "");
			told_edit_icon.setEnabled(true);
			told_edit_icon.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (mToldDetailListener != null) {
						mToldDetailListener.onToldDetailonClick(item);
					}
				}
			});
		}
	}
}
